package org.luxor.system.transform;

import org.luxor.system.entity.SysMenuEntity;
import org.luxor.system.entity.vo.router.MenuVo;
import org.luxor.system.entity.vo.router.MetaVo;

import java.util.ArrayList;

/**
 * 菜单信息转换器
 *
 * @author YanXinMing @date 2024/9/23
 */
public class MenuTransform {
    public static MenuVo toMenuVo(SysMenuEntity menu, ArrayList<MenuVo> children) {
        MenuVo routerMenu = new MenuVo();
        routerMenu.setName(menu.getName());
        routerMenu.setPath(menu.getPath());
        routerMenu.setComponent(menu.getComponent());
        routerMenu.setRedirect(menu.getRedirect());
        routerMenu.setMeta(toMetaVo(menu));
        routerMenu.setChildren(children);
        return routerMenu;
    }

    private static MetaVo toMetaVo(SysMenuEntity menu) {
        MetaVo meta = new MetaVo();
        meta.setTitle(menu.getTitle());
        meta.setIcon(menu.getIcon());
        meta.setFrameSrc(menu.getFrameSrc());
        meta.setFrameBlank(menu.getFrameBlank());
        meta.setOrderNo(menu.getOrderNo());
        meta.setHidden(menu.getHidden());
        return meta;
    }

}
